package com.gxa.controller;


import com.gxa.pojo.Role;
import com.gxa.service.impl.RoleServiceImpl;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "角色信息管理")
public class RoleController {

    @Autowired

    private RoleServiceImpl roleService;

    /**
     * 添加数据
     *
     * @param role 主键
     * @return 添加是否成功
     */
    @PostMapping("/insertRole")
    @ApiOperation("角色管理信息添加")
    public ResponseData insertRole(@RequestBody Role role) {

        if (roleService.insertRole(role)) {
            return new ResponseData(1, "添加成功");
        } else {
            return new ResponseData(0, "添加失败");
        }
    }

    //@DeleteMapping("/add")
    @GetMapping("/showRole")
    @ApiOperation(value = "显示角色信息",httpMethod = "POST")
    @ResponseBody
    public ResponseData showRole(@ApiParam(value = "显示第几页",required = true) Integer pageNum, @ApiParam(value = "每页显示几条",required = true) Integer pageSize){

        if(roleService.showRole(pageNum,pageSize)!=null){
            return new ResponseData(1,"显示成功",roleService.showRole(pageNum,pageSize));
        }else {
            return new ResponseData(0,"显示失败");
        }
    }
    @ApiOperation("删除角色信息")
    @DeleteMapping("/deleteRole")
    @ResponseBody
    public ResponseData deleteRole(Role role) {
        ResponseData responseData = new ResponseData();
        if (this.roleService.deleteRole(role)){
            responseData.setMsg("success");
        }else {
            responseData.setCode(404);
            responseData.setMsg("fail");
        }
        return responseData;
    }
}
